package com.yotoodesign.dianba.ui;

import android.util.Log;

import com.baidu.location.BDLocation;
import com.baidu.location.BDLocationListener;
import com.yotoodesign.dianba.fragment.KtvFragment;
import com.yotoodesign.dianba.util.Constant;
/*

04-13 22:20:35.718: I/DIANBA(27469): onReceiveLocation>>>>>>time : 2013-04-13 22:20:20
04-13 22:20:35.718: I/DIANBA(27469): error code : 161
04-13 22:20:35.718: I/DIANBA(27469): latitude : 31.837868
04-13 22:20:35.718: I/DIANBA(27469): lontitude : 117.321773
04-13 22:20:35.718: I/DIANBA(27469): radius : 11.6
04-13 22:20:35.718: I/DIANBA(27469): addr : 安徽省合肥市包河区当涂支路
 
 */

public class MyLocationListener  implements BDLocationListener{
	
	private BDLocation location;
	
	private KtvFragment ktvRef;
	
	public KtvFragment getKtvRef() {
		return ktvRef;
	}

	public void setKtvRef(KtvFragment ktvRef) {
		this.ktvRef = ktvRef;
	}

	public BDLocation getLocation() {
		return location;
	}

	public void setLocation(BDLocation location) {
		this.location = location;
	}

	@Override
	public void onReceiveLocation(BDLocation location) {
		//更新位置信息
		ktvRef.updateLocation(location);
		
		if (location == null)
			return ;
		StringBuffer sb = new StringBuffer(256);
		sb.append("time : ");
		sb.append(location.getTime());
		sb.append("\nerror code : ");
		sb.append(location.getLocType());
		sb.append("\nlatitude : ");
		sb.append(location.getLatitude());
		sb.append("\nlontitude : ");
		sb.append(location.getLongitude());
		sb.append("\nradius : ");
		sb.append(location.getRadius());
		if (location.getLocType() == BDLocation.TypeGpsLocation){
			sb.append("\nspeed : ");
			sb.append(location.getSpeed());
			sb.append("\nsatellite : ");
			sb.append(location.getSatelliteNumber());
		} else if (location.getLocType() == BDLocation.TypeNetWorkLocation){
			sb.append("\naddr : ");
			sb.append(location.getAddrStr());
		} 
 
	}
	
	public void onReceivePoi(BDLocation poiLocation) {
		if (poiLocation == null){
			return ;
		}
		StringBuffer sb = new StringBuffer(256);
		sb.append("Poi time : ");
		sb.append(poiLocation.getTime());
		sb.append("\nerror code : ");
		sb.append(poiLocation.getLocType());
		sb.append("\nlatitude : ");
		sb.append(poiLocation.getLatitude());
		sb.append("\nlontitude : ");
		sb.append(poiLocation.getLongitude());
		sb.append("\nradius : ");
		sb.append(poiLocation.getRadius());
		if (poiLocation.getLocType() == BDLocation.TypeNetWorkLocation){
			sb.append("\naddr : ");
			sb.append(poiLocation.getAddrStr());
		} 
		if(poiLocation.hasPoi()){
			sb.append("\nPoi:");
			sb.append(poiLocation.getPoi());
		}else{				
			sb.append("noPoi information");
		}
		
	}
}
